package com.cloudkinto.appletController.orderwork;


import com.cloudkinto.appletservice.orderwork.AppletOrderWorkService;
import com.cloudkinto.base.BaseController;
import com.cloudkinto.common.annotations.UserSessionRequired;
import com.cloudkinto.common.web.PageResult;
import com.cloudkinto.common.web.SingleResult;
import com.cloudkinto.service.orderwork.OrderWorkService;
import com.cloudkinto.service.orderwork.vo.OrderWorkAddReq;
import com.cloudkinto.service.orderwork.vo.OrderWorkUpdateReq;
import com.cloudkinto.service.product.ProductInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author zhangyy
 * @since 2020-06-18
 */
@RestController
@Api(tags = "小程序定制工单模块")
@RequestMapping("/api/applet/orderWork")
public class AppletOrderWorkController extends BaseController {
    private final Logger logger = LoggerFactory.getLogger(AppletOrderWorkController.class);

    @Autowired
    private AppletOrderWorkService service;


    @UserSessionRequired
    @GetMapping("/{id}")
    @ApiOperation(value = "根据id查看详情", notes = "根据id查看详情")
    public SingleResult detail(@PathVariable("id") Long id) {
        return SingleResult.success("查询成功",service.detail(id));
    }


    @UserSessionRequired
    @GetMapping("/listPage")
    @ApiOperation(value = "查询（分页）", notes = "查询（分页）")
    @ApiImplicitParams({@ApiImplicitParam(name = "status", value = "流转状态")
            , @ApiImplicitParam(name = "orderWorkType", value = "工单类型")
            , @ApiImplicitParam(name = "current", value = "")
            , @ApiImplicitParam(name = "pageSize", value = "")
            , @ApiImplicitParam(name = "keyword", value = "")})
    public PageResult listPage(HttpServletRequest request) {
        Long companyId = getCompanyId();

        Map<String, String> map = new HashMap<>();
        String keyword = request.getParameter("keyword");
        String status = request.getParameter("status");
        String orderWorkType = request.getParameter("orderWorkType");
        String current = request.getParameter("current");
        String size = request.getParameter("pageSize");
        map.put("keyword", keyword);
        map.put("status", status);
        map.put("orderWorkType", orderWorkType);
         if (getShopId() != null) {
            map.put("shopId", getShopId()+"");
        }
        map.put("companyId", String.valueOf(companyId));
        map.put("current", current);
        map.put("pageSize", size);
        return service.getListPage(map);
    }


}

